﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.HtmlControls;


namespace MediaMonitor.Common
{

    public class AjaxFuncs
{
 

	public static void MsgBox(Page page, string msg)
	{
		//msg = RemoveHTML(msg)
		msg = msg.Replace("\"", "\\\"");
		msg = msg.Replace("'", "\\'");
		 

		// Anthem.Manager.AddScriptForClientSideEval("alert('" & msg & "')")
        ScriptManager.RegisterClientScriptBlock(page, "".GetType(), "jsm" + GetRandomCode(), "alert('" + msg + "')", true);

	}

    public static bool ConfirmBox(Page page, string msg, string hiddenField2Set) {
        //msg = RemoveHTML(msg)
        msg = msg.Replace("\"", "\\\"");
        msg = msg.Replace("'", "\\'");


        // Anthem.Manager.AddScriptForClientSideEval("alert('" & msg & "')")
        ScriptManager.RegisterClientScriptBlock(page, "".GetType(), "jsc" + GetRandomCode(), "document.getElementById('" + hiddenField2Set + "').value = confirm('" + msg + "')", true);

        return false;
    }

	public static void RegisterScript(Page page, string script)
	{
		//msg = RemoveHTML(msg)
		script = script.Replace("\"", "\\\"");
		script = script.Replace("'", "\\'");
		//script = script.Replace(Constants.vbCrLf, "\\n");

		// Anthem.Manager.AddScriptForClientSideEval("alert('" & msg & "')")
        ScriptManager.RegisterClientScriptBlock(page, "".GetType(), "jsr" + GetRandomCode(), script, true);

	}

    public static void RunJS(Page page, string script)
    {
        //msg = RemoveHTML(msg)
        script = script.Replace("\"", "\\\"");
        script = script.Replace("'", "\\'");
        //script = script.Replace(Constants.vbCrLf, "\\n"); 

        ScriptManager.RegisterStartupScript(page, "".GetType(), "jss" + GetRandomCode(), script, true);

    }
 
	public static void Redirect(Page curPage, string url)
	{
		ScriptManager.RegisterClientScriptBlock(curPage, "".GetType(), "ajaxredirect", "window.open('" + url + "', '_parent')", true);
	}
       

    private static string GetRandomCode()
    {
        return new Random().NextDouble().ToString().Replace(".", "");

    }

    public static void LoginScreen(Page aspxPage, bool show)
     {
    //    try {
            
    //        AjaxControlToolkit.ModalPopupExtender screen = (AjaxControlToolkit.ModalPopupExtender)aspxPage.Master.FindControl("LoginStatus").FindControl("SignUpModel");


    //        if ((screen == null))
    //            return;

    //        if (show == true) {
    //            screen.Show();

    //        } else {
    //            screen.Hide();
    //        }
    //    } catch {
    //    }
   }
 
	 
}
    
}